#include<stdio.h>

int mycat(const char *path);

int main(int argc, char *argv[])
{
	if(argc < 2)
		return 1;
	mycat(argv[1]);
	return 0;
}

int mycat(const char *path)
{
	FILE * fp = NULL;
	int c;

	fp = fopen(path, "r");
	if(NULL == fp){
		perror("fopen()");
		return -1;
	}
	while(1){
		c  = fgetc(fp);
		if(c == EOF){
			if(ferror(fp)){
				goto ERROR;
			}
			break;
		}
		fputc(c, stdout);
	}
	fclose(fp);
	return 0;
ERROR:
	fclose(fp);
	return -1;
}

